<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

require_once ADMIN.DS."/head.php";
?>
<h1>Список страховщиков</h1>
<br />
<a href="/admin/companies" <?php
if ($route->GET("type") != "branches" && $route->GET("type") != "head"){
	echo "style='font-weight:bold'";
}
?>>Все головные офисы</a> | <a href="/admin/companies?type=head" <?php
if ($route->GET("type") == "head"){
	echo "style='font-weight:bold'";
}
?>>Головные офисы в <?php echo $current_admin_city['name_pred']; ?></a> | <a href="/admin/companies?type=branches" <?php
if ($route->GET("type") == "branches"){
	echo "style='font-weight:bold'";
}
?>>Филиалы в <?php echo $current_admin_city['name_pred']; ?></a><br />
<?php
	if ($route->GET("order") == "success"){
		echo "<p class='success'><br />Успешно обновлено</p>";
	} elseif ($route->GET("order") == "fail") {
		echo "<p class='fail'><br />Не удалось обновить</p>";
	}
?><br />
<input type="text" placeholder="Поиск..." id="search" />
<br /><br />
<div class='floating'><a href='/admin/companies/add'>Добавить компанию</a></div>
<table cellpadding='0' cellspacing='0' class='list' id="table">
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='300px'>Название</td>
		<td width='130px'>Значение</td>
		<td width='70px'>Приоритет</td>
		<td width='200px' class='actions'>Действия</td>
	</tr><?php
		if ($route->GET("type") == "head"){
			$query = "select * from `companies` where `city_id` = '".$current_admin_city['city_id']."' and `head_office` = '0' order by `name`";
		} elseif ($route->GET("type") == "branches") {
			$query = "select * from `companies` where `city_id` = '".$current_admin_city['city_id']."' and `head_office` != '0' order by `name`";
		} else {
			$query = "select * from `companies` where `head_office` = '0' order by `name`";
		}
		$companies = $db->getTable($query);
		foreach ($companies as $company)
		{
			echo "<tr class='tr'><td>$company[company_id]</td>";
			echo "<td class='find'>$company[name]</td>";
			echo "<td>".($company['head_office'] ? "Филиал" : "Головной офис")."</td>";
			echo "<td style='text-align: center;'>";
				echo "<form action='/admin/companies/editorder/$company[company_id]' method='post'>";
					echo "<input type='text' name='order' style='width:50px; text-align:center' value='$company[order]' />";
				echo "</form>";
			echo "</td>";
			echo "<td class='actions'><a href='/admin/companies/edit/$company[company_id]' class='edit'>Редактировать</a> | <a href='/admin/companies/delete/$company[company_id]' class='delete'>Удалить</a></td></tr>";
		}
?></table>

<?php require_once ADMIN.DS."/footer.php"; ?>